import { reactive, onMounted } from 'vue'
import axios, { AxiosError } from 'axios'


export default function () {
  //错误写法：
  //let dogList: string[] = reactive([]) 存在类型问题

  //数据
  let dogList = reactive<string[]>([])

  async function getDog() {
    try {
      //发送请求
      let { data } = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
      //维护数据
      dogList.push(data.message)

    } catch (error) {
      //处理错误
      const err = <AxiosError>error
      console.log(err.message);

    }
  }

  //挂载钩子
  onMounted(() => { getDog() })

  return { dogList, getDog }


}
